let express = require('express')
// let fs = require('fs')
let router = require('./router')
const bodyParser = require('body-parser')//用来获取表单post请求体数据
let app = express()
app.engine('html', require('express-art-template'))
app.use('/public', express.static('./public'))

app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
var allowCors = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', req.headers.origin);
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header('Access-Control-Allow-Credentials','true');
    next();
  };
  app.use(allowCors);//使用跨域中间件
//使用路由
app.use(router)

app.listen(80, () => {
    console.log('server running');

})